package com.humh.library.v2.model;


import com.humh.library.model.Fine;
import com.humh.library.model.LoanRecord;
import java.util.ArrayList;
import java.util.List;

// 读者类

public class Reader {
  private String readerId;
  private String name;
  private String email;
  private List<LoanRecord> loanRecords;
  private Fine fine; //罚金

  public Reader(String readerId, String name, String email) {
    this.readerId = readerId;
    this.name = name;
    this.email = email;
    this.loanRecords = new ArrayList<>();
    this.fine = new Fine(0);

  }

    /**
   * 添加借阅记录
   * @param loanRecord
   */
  public void addLoanRecord(LoanRecord loanRecord) {
    loanRecords.add(loanRecord);
  }


  /**
   * 支付罚款
   * @param amount
   */
  public boolean payFine(double amount) {
    addFine(amount);
    fine.payFine(amount);
    return fine.isPaid();
  }

  /**
   * 判断是否有超期图书
   * @return
   */
  public boolean hasOverdueBooks() {
    for (LoanRecord loanRecord : loanRecords) {
      if (loanRecord.isOverdue()) {
        return true;
      }
    }
    return false;
  }

  /**
   * 添加罚款
   * @param amount
   */
  private void addFine(double amount) {
    this.fine.setAmount(amount);
  }

  // Getters and Setters
  public String getReaderId() {
    return readerId;
  }

  public void setReaderId(String readerId) {
    this.readerId = readerId;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public List<LoanRecord> getLoanRecords() {
    return loanRecords;
  }

}

